package com.java.basis.collection.set;

import java.util.TreeSet;

/**
 * Comparator:比较器
 * @author wangning
 * @create 2021-04-22 22:35
 */
public class TestTreeSet03 {

	public static void main(String[] args) {
		TreeSet<Person> persons = new TreeSet<>((o1, o2) -> {
			int n1 = o1.getAge() - o2.getAge();
			int n2 = o1.getName().compareTo(o2.getName());
			return n1 == 0 ? n2 : n1;
		});
		Person person = new Person("xyz",20);
		Person person1 = new Person("hello",22);
		Person person2 = new Person("zhangsan",25);
		Person person3 = new Person("lisi",25);
		persons.add(person);
		persons.add(person1);
		persons.add(person2);
		persons.add(person3);
		System.out.println(persons.toString());

	}
}
